package com.unione.unione_base.view

import android.os.Handler
import android.os.Looper
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.unione.unione_base.bean.BaseRobotRepo

/**
 * 为后面扩展用
 */
open class BaseViewModel : ViewModel() {


    /** 请求异常（服务器请求失败，譬如：服务器连接超时等） */
    val exception = MutableLiveData<Exception>()

    /** 请求服务器返回错误（服务器请求成功但status错误，譬如：登录过期等） */
    val errorResponse = MutableLiveData<BaseRobotRepo<*>?>()

     var TIMEOUT = 15 * 1000 //超时时间
    //处理超时
    var mHandler = Handler(Looper.getMainLooper())
    val liveDataTimeOut = MutableLiveData<Boolean>()
     fun addTimeout() {
        mHandler.postDelayed(timeoutRunable, TIMEOUT.toLong())
    }

     fun removeTimeout() {
        mHandler.removeCallbacks(timeoutRunable)
    }
    private var timeoutRunable = Runnable { liveDataTimeOut.postValue(true) }
}